import { Layout, Menu } from 'antd';
import "./Home.scss";
import React from 'react'
import { Link, Outlet } from 'react-router-dom'
import touxiang from "../../static/images/Home_touxiang.svg"
import { useEffect, useState } from 'react';
import http from '../../utils/http'
import { useNavigate } from 'react-router-dom';
import store from '../../store';
const { Header, Content } = Layout;

const Home = () => {
  const navigate = useNavigate()
  const [items2, setitems2] = useState([])
  const [name, setname] = useState(sessionStorage.getItem("name"));
  let arr = []
  let items = []
  const data = [
    {
      label: '综合态势',
      key: '1',
      link: '/home/ComprehensiveSituational'
    },
    {
      label: '运营管理',
      key: '2',
      link: '/home/Operate/OperationOverview'
    },
    {
      label: '物业管理',
      key: '3',
      link: '/home/Property/PropertyOverview'
    },
    {
      label: '数据可视',
      key: '4',
      link: '/home/Visual/ParkCockpit'
    },
    {
      label: '配置中心',
      key: '5',
      link: '/home/Set/ProjectManagement'
    },
  ];

  useEffect(() => {
    // const name = sessionStorage.getItem("name");
    const id = sessionStorage.getItem("id");
    // store.wuxiaoyuan.setOperator(id)
    // let myname = sessionStorage.getItem("name")
    // setname(myname)
    // cosnt[name, setname] = useState(sessionStorage.getItem("name"))

    data.forEach((v, i) => {
      if (id != 1) {
        if (v.label != '配置中心') {
          arr.push(v)
        }
      }
      else {
        arr.push(v)
      }
    })
    items = arr.map((v, i) => {
      return {
        key: v.key,
        label: <Link to={v.link}>{v.label}</Link>
      }
    });
    console.log(items)
    setitems2(items)
  }, [])
  const [current, setCurrent] = React.useState('situation');
  const onClick = (e) => {
    console.log('click ', e);
    setCurrent(e.key);
  };
  const exit = () => {
    http({
      url: '/index/quit',
      method: 'post'
    }).then((res) => {
      console.log(res);
      if (res.code == 200) {
        navigate('/login')
        // sessionStorage.setItem('table', JSON.stringify(arr));
      }
    })
  }
  return (
    <Layout className="home">
      <Header className='myhome'>
        <div>
          <div className='tit'>智慧园区管理平台</div>
          <Menu onClick={onClick} selectedKeys={[current]} mode="horizontal" items={items2} />
          <div className='message'>
            <div>
              <span className="iconfont">&#xe633;</span>
            </div>
            <div>
              <img src={touxiang} alt=""></img>
            </div>
            <div>{name}</div>
            <div onClick={exit}>exit</div>
          </div>
        </div>
      </Header>
      <Content>
        <Outlet />
      </Content>
    </Layout >
  )
};

export default Home;
